package cn.edu.ctbu.springbootnewtest.service;

import cn.edu.ctbu.springbootnewtest.domain.Student;
import cn.edu.ctbu.springbootnewtest.repository.StudentRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StudentService {
    @Autowired
    private StudentRepository studentRepository;
    public List<Student> findAll(){
        return studentRepository.findAll();
    }
    public Student findById(Integer id){
        return studentRepository.findById(id).orElse(null);
    }

    public List<Student> findByName(String name){

        return studentRepository.findByNameLike(name);
    }

    public List<Student> findByNameAndPassword(String name, String password) {
        return studentRepository.findByNameAndPassword(name,password);
    }
    public Student insert(Student student){

        return studentRepository.save(student);
    }

    public void delete(Integer id){
        studentRepository.deleteById(id);
    }
    public List<Student> findByNoLike (String no){
        return studentRepository.findByNoLike(no);
    }
}

